<!DOCTYPE html>
<!--suppress ALL-->
<html xmlns:th="https://www.thymeleaf.org/">
<head>
    <meta charset="UTF-8">
    <title>Thymeleaf</title>
    <script type="text/javascript" src="/jquery-3.4.1.min.js"></script>
    <script>
        $(function(){
            $("#a1").click(function(){
               let id = $(this).attr("data-id");
               console.log("id:"+id)
            });
        })
    </script>
</head>
<body>
<h2>访问request作用域数据</h2>
<h2>不识别标签</h2>
<!--此处代码运行没问题,显示出现报错,属于IDEA校验问题-->
<span th:text="${msg}"></span>
[[${msg}]]
<h2>识别标签</h2>
<!--<span th:utext="${msg}"></span>-->
[(${msg})]
<hr>
<h2>访问session作用域数据</h2>
用户名:<span th:text="${session.user.username}"></span><br>
密码:[[${session.user.password}]]
<hr>
<h2>访问application作用域数据</h2>
用户名:<span th:text="${application.user2.username}"></span><br>
密码:[[${application.user2.password}]]
<hr>
<h2>属性赋值</h2>
<a href="javascript:;" id="a1" th:data-id="${id}">修改</a>
<hr>
<h2>if判断</h2>
<span th:if="${age < 5}">婴儿</span>
<span th:if="${age < 18}">少年</span>
<span th:if="${age < 30}">青年</span>
<span th:if="${age < 60}">中年</span>
<span th:if="${age >= 60}">老年</span>
<h2>unless判断</h2>
<span th:unless="${age < 5}">婴儿</span>
<span th:unless="${age < 18}">少年</span>
<span th:unless="${age < 30}">青年</span>
<span th:unless="${age < 60}">中年</span>
<span th:unless="${age >= 60}">老年</span>
<h2>switch判断</h2>
<span th:switch="${role}">
<!--    <span th:case="student">学生</span>-->
    <span th:case="user">用户</span>
    <span th:case="staff">员工</span>
    <span th:case="teacher">教师</span>
    <span th:case="programmer">程序员</span>
    <span th:case="*">其他</span>
</span>
<hr>
<h2>遍历</h2>
<table border="1">
    <tr>
        <th>序号</th>
        <th>编号</th>
        <th>用户名</th>
        <th>密码</th>
    </tr>
<!--    <tr th:each="user:${users}">-->
    <tr th:each="user,i:${users}">
        <td th:text="${i.index+1}"></td>
        <td th:text="${user.id}"></td>
        <td th:text="${user.username}"></td>
        <td th:text="${user.password}"></td>
    </tr>
</table>
<hr>
<h2>设置默认值</h2>
<form action="">
    编号:<input type="text" th:value="${user.id}"><br>
    用户名:<input type="text" th:value="${user.username}"><br>
    密码:<input type="password" th:value="${user.password}"><br>
    <input type="submit" value="修改">
</form>
<hr>
<form action="">
    编号:<input type="text" th:field="${user.id}"><br>
    用户名:<input type="text" th:field="${user.username}"><br>
    密码:<input type="password" th:field="${user.password}"><br>
    <input type="submit" value="修改">
</form>
<hr>
<form action="" th:object="${user}">
    编号:<input type="text" th:field="*{id}"><br>
    用户名:<input type="text" th:field="*{username}"><br>
    密码:<input type="password" th:field="*{password}"><br>
    <input type="submit" value="修改">
</form>

<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</body>
</html>